<html>
<%@ include file="../../common/taglibs.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title><fmt:message key="format.message.system" /></title>

<script type="text/javascript" >
Ext.namespace('azure', 'azure.common');
azure.common.atention = function() {
	var cm_atention;
	var grid_atenton, store_atenton;
	var mainpanel;
	var toolbar_res;
	var addAtentonForm,editAtentonForm;
	var addAtentonWin,editAtentonWin

	// 創建ColumnModel
	function createCM() {
		cm_atention = new Ext.grid.ColumnModel([
		{header : '<fmt:message key="format.atention.Number" />',dataIndex : 'affId'},
		{header : '<fmt:message key="format.atention.atentionTitle" />',dataIndex : 'title'}, 
		{header : '<fmt:message key="format.atention.contents" />',dataIndex : 'contents'},
		{header : '<fmt:message key="format.atention.atentiontime" />',dataIndex : 'createTime',sortable : true}, 
		{
			header : '<fmt:message key="format.atention.atentiontype" />',
			dataIndex : 'type',
			renderer : function(value) {
				if (value == 1) {
					return '<fmt:message key="format.atention.atentiontype0" />';
				} else {
					return '<fmt:message key="format.atention.atentiontype1" />';
				}
			}
		}]);
	}

	function createStore() {
		store_atenton = new Ext.data.Store({
			id:'atentionStore',
			proxy : new Ext.data.HttpProxy({
				url : 'Affiche_findByPage.action'
			}),
			reader : new Ext.data.JsonReader({
				root : 'affes.data',
				totalProperty : 'affes.totalSize'
			}, [{
			name : 'affId',
			mapping : 'affId'
		}, {
			name : 'title',
			mapping : 'title'
		}, {
			name : 'contents',
			mapping : 'contents'
		}, {
			name : 'createTime',
			mapping : 'createTime'
		}, {
			name : 'type',
			mapping : 'type'
		}])
		});

	}

	function createToolbar() {
		toolbar_res = new Ext.Toolbar([{
			text : '<fmt:message key="format.atention.add" />',
			handler : addNew
		}, {
			text : '<fmt:message key="format.atention.update" />',
			handler : doEdit
		}, {
			text : '<fmt:message key="format.atention.delete" />',
			handler : function() {
				var dict = grid_atenton.getSelections()[0];
				if (dict != null) {
					Ext.MessageBox.confirm('<fmt:message key="format.content.delete" />', '<fmt:message key="format.content.isdelete" />', doDel)
				} else {
					Ext.MessageBox.alert('<fmt:message key="format.content.Tips" />', '<fmt:message key="format.content.aterror" />');
				}
			}
		}]);
	}
	function createGrid() {
		createCM();
		createStore();
		createToolbar();

		grid_atenton = new Ext.grid.GridPanel({
			cm : cm_atention,
			store : store_atenton,
			height :500,
			layout:'fit',				
			bbar : new Ext.PagingToolbar({
				grid : grid_atenton,
				store : store_atenton,
				pageSize : 15,
				displayInfo : true,
				displayMsg : '<fmt:message key="format.content.pager" />',
				emptyMsg : '<fmt:message key="format.content.emptyMsg" />'
			})
		});
		store_atenton.on('beforeload', function() {
			Ext.apply(this.baseParams, {
				type: ''
			});
		});
		
		store_atenton.load({params:{
			start:0,
			limit:15
		}});

	}

	function createUI() {
		createGrid();
		createForm();
		mainpanel = new Ext.Panel({
			frame : false,
			renderTo : 'atentionDiv',
			items : [toolbar_res, grid_atenton]
		});
	}

	function createForm() {
		addAtentonForm = new Ext.form.FormPanel({
			id:'addatention',
			labelWidth : 115,
			frame : true,
			url:'Affiche_create.action',
			labelSeparator : ':',
			labelAlign : 'right',
			defaultType : 'textfield',
			items : [new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.atention.atentionTitle" />',
				width : 220,
				name : 'affiche.title'
			}),new Ext.form.HtmlEditor({
				fieldLabel : '<fmt:message key="format.atention.contents" />',
				name : 'affiche.contents',
				width : 500,
				labelWidth : 50,
				anchor : '99%'
			}), {
                xtype: 'radiogroup',
                fieldLabel: '<fmt:message key="format.atention.atentiontype" />',
                items: [
                    {boxLabel: '<fmt:message key="format.atention.atentiontype0" />', name: 'affiche.type', inputValue: 1,checked: true},
                    {boxLabel: '<fmt:message key="format.atention.atentiontype1" />', name: 'affiche.type', inputValue: 0}
                ]
            }]
		});

		editAtentonForm = new Ext.form.FormPanel({
			labelWidth : 115,
			frame : true,
			url:'Affiche_update.action',
			labelSeparator : ':',
			labelAlign : 'right',
			defaultType : 'textfield',
			items : [new Ext.form.Hidden({
				name : 'affId'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.atention.atentionTitle" />',
				width : 220,
				name : 'title'
			}),new Ext.form.HtmlEditor({
				fieldLabel : '<fmt:message key="format.atention.contents" />',
				name : 'contents',
				width : 500,
				labelWidth : 50,
				anchor : '99%'
			}),{
                xtype: 'radiogroup',
                fieldLabel: '<fmt:message key="format.atention.atentiontype" />',
                items: [
                    {boxLabel: '<fmt:message key="format.atention.atentiontype0" />', name: 'type', inputValue: 1},
                    {boxLabel: '<fmt:message key="format.atention.atentiontype1" />', name: 'type', inputValue: 0}
                ]
            }]
		});
	}
	function addNew() {
		addAtentonWin = new Ext.Window({
			width : 800,
			height : 520,
			closable : false,
			layout : 'fit',
			items : addAtentonForm,
			modal : true,
			tbar : [{
				text : '<fmt:message key="format.content.Determine" />',
				handler : create,
				formBind : true
			}, {
				text : '<fmt:message key="format.content.Cancel" />',
				handler : function() {
					addAtentonWin.hide();
				}
			}]
		});

		addAtentonWin.title = '<fmt:message key="format.atention.add" />';
		addAtentonWin.show(Ext.getBody());
	}

	create = function(btn) {
		var addatention = Ext.getCmp('addatention');
		if(addatention.getForm().isValid()){
			btn.disable();
			addatention.getForm().submit({
				method : 'POST',
				waitMsg : '<fmt:message key="format.content.saving" />',
				successProperty : false,
				success : function() {
					Ext.Msg.alert('<fmt:message key="format.content.Success" />', '<fmt:message key="format.content.saveSuccess" />',function() {
						btn.enable();
						store_atenton.reload();
					});
				},
				failure : function() {
					Ext.Msg.alert('<fmt:message key="format.content.Failure" />', '<fmt:message key="format.content.saveFailure" />');
					btn.enable();
				}
			});
			}
	}

	function doEdit() {
		editAtentonWin = new Ext.Window({
			width : 800,
			height : 520,
			closable : false,
			layout : 'fit',
			items : editAtentonForm,
			modal : true,
			tbar : [{
				text : '<fmt:message key="format.content.Determine" />',
				handler: function(btn) {

					if(editAtentonForm.getForm().isValid()){
						btn.disable();
						editAtentonForm.getForm().submit({
							method : 'POST',
							waitMsg : '<fmt:message key="format.content.updating" />',
							successProperty : false,
							success : function() {
								Ext.Msg.alert('<fmt:message key="format.content.Success" />', '<fmt:message key="format.content.updateSuccess" />',function() {
									btn.enable();
									store_atenton.reload();
								});
							},
							failure : function() {
								Ext.Msg.alert('<fmt:message key="format.content.Failure" />', '<fmt:message key="format.content.updateFailure" />');
								btn.enable();
							}
						});
						}
				},
				formBind:true

			}, {
				text : '<fmt:message key="format.content.Cancel" />',
				handler : function() {
					editAtentonWin.hide();
				}
			}]
		});
		var rec = grid_atenton.getSelections()[0];
		if (rec != null) {
			editAtentonWin.title = '<fmt:message key="format.atention.update" />';
			editAtentonWin.show(Ext.getBody());
			editAtentonForm.getForm().loadRecord(rec);
		} else {
			Ext.MessageBox.alert('<fmt:message key="format.content.Warning" />', '<fmt:message key="format.content.aterror" />');
		}

	}
	
	function doDel(d) {
		if (d == 'yes') {
			var r = grid_atenton.getSelectionModel().getSelected();
			var rec = grid_atenton.getSelections()[0];
			
			Ext.MessageBox.wait('<fmt:message key="format.content.wait" />');
			Ext.Ajax.request( {
				url : 'Affiche_delete.action',
				params : {
					'affiche.affId' : rec.data.affId
				},
				success : function(response) {
					grid_atenton.getStore().remove(rec);
					Ext.MessageBox.hide();
				},
				failure : function() {
					Ext.Msg.show( {
						title : '<fmt:message key="format.content.errortitle" />',
						msg : '<fmt:message key="format.content.errormsg" />',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR
					});
				}
			});
		}
	}
	
	return {
		init : function() {
			createUI();
		}
	};

}();
Ext.onReady(azure.common.atention.init, azure.common.atention, true);
</script>
</head>

	<body>
		<div id="atentionDiv"></div>
	</body>
</html>
